/*     */ package com.zimbra.cs.account.auth;
/*     */ 
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.util.ZimbraHttpConnectionManager;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException;
/*     */ import java.io.IOException;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.httpclient.Header;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpException;
/*     */ import org.apache.commons.httpclient.HttpMethod;
/*     */ import org.apache.commons.httpclient.methods.GetMethod;
/*     */ import org.apache.commons.httpclient.methods.PostMethod;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class HostedAuth
/*     */   extends ZimbraCustomAuth
/*     */ {
/*  38 */   public static String HEADER_AUTH_USER = "Auth-User";
/*  39 */   public static String HEADER_AUTH_PASSWORD = "Auth-Pass";
/*  40 */   public static String HEADER_AUTH_PROTOCOL = "Auth-Protocol";
/*     */   
/*  42 */   public static String HEADER_CLIENT_IP = "Client-IP";
/*  43 */   public static String HEADER_AUTH_STATUS = "Auth-Status";
/*     */   
/*     */ 
/*  46 */   public static String HEADER_AUTH_USER_AGENT = "Auth-User-Agent";
/*  47 */   public static String HEADER_X_ZIMBRA_REMOTE_ADDR = "X-ZIMBRA-REMOTE-ADDR";
/*     */   
/*  49 */   public static String AUTH_STATUS_OK = "OK";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void authenticate(Account acct, String password, Map<String, Object> context, List<String> args)
/*     */     throws Exception
/*     */   {
/*  60 */     HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient();
/*  61 */     HttpMethod method = null;
/*     */     
/*  63 */     String targetURL = (String)args.get(0);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  73 */     if (args.size() > 1) {
/*  74 */       if (((String)args.get(1)).equalsIgnoreCase("GET")) {
/*  75 */         method = new GetMethod(targetURL);
/*     */       } else
/*  77 */         method = new PostMethod(targetURL);
/*     */     } else {
/*  79 */       method = new GetMethod(targetURL);
/*     */     }
/*  81 */     if (context.get("ocip") != null) {
/*  82 */       method.addRequestHeader(HEADER_CLIENT_IP, context.get("ocip").toString());
/*     */     }
/*  84 */     if (context.get("remoteip") != null) {
/*  85 */       method.addRequestHeader(HEADER_X_ZIMBRA_REMOTE_ADDR, context.get("remoteip").toString());
/*     */     }
/*  87 */     method.addRequestHeader(HEADER_AUTH_USER, acct.getName());
/*  88 */     method.addRequestHeader(HEADER_AUTH_PASSWORD, password);
/*     */     
/*  90 */     AuthContext.Protocol proto = (AuthContext.Protocol)context.get("proto");
/*     */     
/*  92 */     if (proto != null) {
/*  93 */       method.addRequestHeader(HEADER_AUTH_PROTOCOL, proto.toString());
/*     */     }
/*  95 */     if (context.get("ua") != null) {
/*  96 */       method.addRequestHeader(HEADER_AUTH_USER_AGENT, context.get("ua").toString());
/*     */     }
/*     */     try {
/*  99 */       HttpClientUtil.executeMethod(client, method);
/*     */     } catch (HttpException ex) {
/* 101 */       throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(acct.getName(), acct.getName(), "HTTP request to remote authentication server failed", ex);
/*     */     } catch (IOException ex) {
/* 103 */       throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(acct.getName(), acct.getName(), "HTTP request to remote authentication server failed", ex);
/*     */     } finally {
/* 105 */       if (method != null) {
/* 106 */         method.releaseConnection();
/*     */       }
/*     */     }
/* 109 */     int status = method.getStatusCode();
/* 110 */     if (status != 200) {
/* 111 */       throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(acct.getName(), "HTTP request to remote authentication server failed. Remote response code: " + Integer.toString(status));
/*     */     }
/*     */     
/*     */     String responseMessage;
/* 115 */     if (method.getResponseHeader(HEADER_AUTH_STATUS) != null) {
/* 116 */       responseMessage = method.getResponseHeader(HEADER_AUTH_STATUS).getValue();
/*     */     } else
/* 118 */       throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(acct.getName(), "Empty response from remote authentication server.");
/*     */     String responseMessage;
/* 120 */     if (responseMessage.equalsIgnoreCase(AUTH_STATUS_OK)) {
/* 121 */       return;
/*     */     }
/* 123 */     throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(acct.getName(), responseMessage);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/auth/HostedAuth.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */